﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}
<body>
    <div id="app2"> 
        <el-form label-position="right" label-width="80px" :model="fromdata">
            <el-form-item label="姓名">
                <el-input v-model="fromdata.s_name"></el-input>
            </el-form-item>
            <el-form-item label="性别">
                <el-input v-model="fromdata.s_sex"></el-input>
            </el-form-item>
            <el-form-item label="出生日期">
                <el-input v-model="fromdata.s_birth"></el-input>
            </el-form-item>
            <el-form-item label="籍贯">
                <el-input v-model="fromdata.s_native"></el-input>
            </el-form-item>
            <el-form-item label="学位">
                <el-input v-model="fromdata.s_degree"></el-input>
            </el-form-item>
            <el-form-item label="地址">
                <el-input v-model="fromdata.s_address"></el-input>
            </el-form-item>
            <el-form-item label="手机">
                <el-input v-model="fromdata.s_phone"></el-input>
            </el-form-item>
            <el-form-item label="工龄">
                <el-input v-model="fromdata.s_standing"></el-input>
            </el-form-item>
            <el-form-item label="工资">
                <el-input v-model="fromdata.s_salary"></el-input>
            </el-form-item>
            <el-button type="primary" v-on:click="submitForm('fromdata')">提交</el-button>
        </el-form>
    </div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        var app2 = new Vue({
            el: '#app2',
            data: {
                fromdata: {
                    s_name: '',
                    s_sex: '',
                    s_birth: '',
                    s_native: '',
                    s_degree: '',
                    s_address: '',
                    s_phone: '',
                    s_standing: '',
                    s_salary: ''
                }
            },
            methods: {
                submitForm() {
                    if (this.fromdata.s_name == "" || this.fromdata.s_sex == "" || this.fromdata.s_birth == "" || this.fromdata.s_native == "" || this.fromdata.s_degree == "" || this.fromdata.s_address == ""
                        || this.fromdata.s_phone == "" || this.fromdata.s_standing == "" || this.fromdata.s_salary == "") {
                        alert("请输入完整的信息");
                    }
                    else if (isNaN(this.fromdata.s_salary) || isNaN(this.fromdata.s_standing)) {
                        alert("请输入正确的信息");
                    }
                    else if (this.fromdata.s_sex != "男" && this.fromdata.s_sex != "女") {
                        alert("请输入正确的性别信息");
                    }
                    else {
                        axios.post("/test/addStaff", { user: "adamin", s: this.fromdata })
                            .then(function (response) {
                                if (response.data == 1)
                                    alert("添加成功");
                                else
                                    alert("添加失败");
                            });}
                },
            }
        })

    </script>
</body>
